angular.module('start.user.ordercomment.ctrl', [])

  .controller('ordercommentCtrl', function($stateParams, $ionicHistory, $$UserOrderService, $scope, $rootScope, $location, $ionicLoading) {
    console.log("ordercommentCtrl");

    $scope.orderId = $stateParams.orderId;
    if ($scope.orderId == null || $scope.orderId == "") {
      $location.path("tab/home");
    }

    $scope.fullgrade = [1, 2, 3, 4, 5];
    $scope.formData = {
      comment: "",
      orderId: $scope.orderId,
      pic: "",
      jobMoralityGrade: 5, //职业道德
      serviceGrade: 5, //服务技能
      speakGrade: 5, //精彩讲解
      type: 0
    };

    if ($rootScope.orderDetail.evaluateComment == undefined) {
    } else {
      $scope.formData = {
        comment: $rootScope.orderDetail.evaluateComment,
        orderId: $scope.orderId,
        pic: $rootScope.orderDetail.complainPic,
        jobMoralityGrade: $rootScope.orderDetail.evaluateJobMoralityGrade, //职业道德
        serviceGrade: $rootScope.orderDetail.evaluateServiceGrade, //服务技能
        speakGrade: $rootScope.orderDetail.evaluateSpeakGrade, //精彩讲解
        type: 0
      };
    }

    // 提交评论信息
    $scope.subordercomment = function() {
      if (!checkText($scope.formData.comment)) {
        $scope.alertPopup("请正确输入评价内容");
        return false;
      }
      $$UserOrderService.orderCommont($scope.orderId, $scope.formData)
        .then(function(res) {
          $ionicLoading.show({
            template: res.msg,
            noBackdrop: true,
            duration: 1500
          });
          $ionicHistory.goBack();
        });
    };

  });
